package com.dehui.traders.ui.market.plate;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.bean.PlateListBean;
import com.dehui.traders.ui.market.platedetail.PlateDetailActivity;
import com.dehui.traders.ui.market.rankdetail.RankDetailActivity;
import com.dehui.traders.utils.BaseRecyclerAdapter;
import com.dehui.traders.utils.SmartViewHolder;

import java.util.Collection;
import java.util.List;

public class PlateAdapter extends BaseRecyclerAdapter<PlateListBean>{

    private final Context context;

    public PlateAdapter(Collection<PlateListBean> collection, Context context) {
        super(collection, R.layout.list_item_plate_market);
        this.context = context;
    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, PlateListBean model, int position) {
        TextView tvTitle = holder.findViewById(R.id.tv_title);
        GridView gvPlate = holder.findViewById(R.id.gv_plate);
        TextView tvMore = holder.findViewById(R.id.tv_more);

        tvTitle.setText(model.name);

        List<PlateListBean.PlateData> data = model.data;
        PlateItemAdapter itemAdapter = new PlateItemAdapter(context, data);
        gvPlate.setAdapter(itemAdapter);
        gvPlate.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PlateListBean.PlateData plateData = data.get(position);
                RankDetailActivity.start(context,plateData.id,plateData.title);
            }
        });

        tvMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PlateDetailActivity.start(context,model.typeCode,model.name);
            }
        });
    }


}
